<?php


namespace app\mall\controller;
use app\data\controller\api\Auth;
use app\mall\logic\orderLogic;
use app\mall_back\model\GoodsLuckyDrawModel;
use app\mall_back\model\TescoCommentModel;

class Comment extends Auth
{
    /**
     * 最新晒单
     */
   public function newList(){
       $page = request()->param('page', 1);
       $limit = request()->param('limit', 10);
       $TescoCommentModel = new TescoCommentModel();
       $list = $TescoCommentModel->with(['commentUser','goodsLuckyDraw.goods'])
           ->order(['id'=>'desc'])
           ->paginate($limit);
       if ($list) {
           foreach ($list as $key => $value) {
               $list[$key]['images_arr'] = explode('|', $value['images']);
           }
       }
       $this->success('晒单记录', $list);
   }


    /**
     * 疯狂晒单
     */
   public function fkList(){
       $page = request()->param('page', 1);
       $limit = request()->param('limit', 10);
       $TescoCommentModel = new TescoCommentModel();
       $list = $TescoCommentModel->where(['recommend_type'=>1])->with(['commentUser','goodsLuckyDraw.goods'])
           ->paginate($limit);
       if ($list) {
           foreach ($list as $key => $value) {
               $list[$key]['images_arr'] = explode('|', $value['images']);
           }
       }
       $this->success('疯狂晒单记录', $list);
   }


    /**
     * 往期晒单
     */
   public function oldList(){
       $page = request()->param('page', 1);
       $limit = request()->param('limit', 10);
       $list = [];
       $goods_lucky_draw_id = request()->param('goods_lucky_draw_id'); //当前期号
       if(!$goods_lucky_draw_id){
           $this->success('往期晒单记录', $list);
       }
       $goodsLuckyDrawModel = GoodsLuckyDrawModel::find($goods_lucky_draw_id);
       if(empty($goodsLuckyDrawModel)){
           $this->success('往期晒单记录', $list);
       }

       $oldgoodsLuckyDrawIds = GoodsLuckyDrawModel::where([
           'goods_id'=>$goodsLuckyDrawModel->goods_id,
       ])->where('id','<>',$goods_lucky_draw_id)->column('id');

       if(empty($oldgoodsLuckyDrawIds)){
           $this->success('往期晒单记录', $list);
       }
       $TescoCommentModel = new TescoCommentModel();
       $list = $TescoCommentModel->where(['recommend_type'=>1])
           ->whereIn('lucky_draw_id',$oldgoodsLuckyDrawIds)
           ->with(['commentUser','goodsLuckyDraw.goods'])
           ->paginate($limit);
       if ($list) {
           foreach ($list as $key => $value) {
               $list[$key]['images_arr'] = explode('|', $value['images']);
           }
       }

       $this->success('往期晒单记录', $list);

   }




}